package inv.cal.view;

import inv.cal.logic.Day;
import inv.cal.logic.EventsInfo;

import java.awt.Component;
import java.util.List;

import javax.swing.JLabel;
import javax.swing.JTable;

public class DayInfoRenderer {
	
	protected void addTooltip(JLabel label, String tooltip){
		String oldtip	= label.getToolTipText();
		if(oldtip == null)
			oldtip = "";
		else
			if(!oldtip.equals("")){
				oldtip	+= ", ";
			}
		oldtip += tooltip;
		label.setToolTipText(oldtip);
	}
	
	protected Component renderHoliday(EventsInfo info,  Component c, JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {

		if(value instanceof Day){
			JLabel label	= (JLabel)c;
			ViewUtil.highlightHoliday(label);
			addTooltip(label, info.getInformation());
		}
		
		return c;
	}
	
	protected Component renderInfo(EventsInfo info, Component c, JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {

		if(value instanceof Day){
			JLabel label	= (JLabel)c;
			ViewUtil.highlightInfo(label);
			addTooltip(label, info.getInformation());
		}
		
		return c;
	}
	
	protected Component renderWarn(EventsInfo info, Component c, JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {

		if(value instanceof Day){
			JLabel label	= (JLabel)c;
			ViewUtil.highlightWarn(label);
			addTooltip(label, info.getInformation());
		}
		
		return c;
	}
	
	public Component render(List<EventsInfo> info, Component c, JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column){
		
		ViewUtil.defaultDay((JLabel)c);
		if(info != null)
			for(EventsInfo day: info){
				switch(day.getType()){
				case HOLIDAY: 	c = renderHoliday(day, c, table, value, isSelected, hasFocus, row, column);
								break;
				case INFO:		c = renderInfo(day, c, table, value, isSelected, hasFocus, row, column);
								break;
				case WARN:		c = renderWarn(day, c, table, value, isSelected, hasFocus, row, column);
								break;
				default:
				}
			}
		
		return c;
	}
	
}
